package com.ilop.sthome.ui.adapter.room;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.common.utils.LiveDataBus;
import com.ilop.sthome.common.CommonId;
import com.siterwell.familywellplus.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author skygge
 * @date 2020/5/22.
 * GitHub：javofxu@github.com
 * email：skygge@yeah.net
 * description：房间推荐
 */
public class RoomRecommendAdapter extends RecyclerView.Adapter<RoomRecommendAdapter.ItemHolder> {

    private Context mContext;
    private String[] mRoomName;

    public RoomRecommendAdapter(Context mContext, String[] list) {
        this.mContext = mContext;
        this.mRoomName = list;
    }

    @NonNull
    @Override
    public ItemHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View mView = LayoutInflater.from(mContext).inflate(R.layout.item_room_recommend, viewGroup, false);
        return new ItemHolder(mView);
    }

    @Override
    public void onBindViewHolder(@NonNull ItemHolder itemHolder, int i) {
        String name = mRoomName[i];
        itemHolder.tvRoomName.setText(name);
        itemHolder.tvRoomName.setOnClickListener(v -> LiveDataBus.get().with(CommonId.KEY_RECOMMEND_ID).setValue(name));
    }

    @Override
    public int getItemCount() {
        return mRoomName.length;
    }

    static class ItemHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_room_name)
        TextView tvRoomName;
        ItemHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
